package br.ufrj.dcc.tp.ns.types;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class NsOutputProcessor {
	private File output;
	private ArrayList<String> values;
	private final String newLine = System.getProperty("line.separator");
	
	public NsOutputProcessor(String path) {
		values = new ArrayList<String>();
		setPath(path);
	}
	
	public void setPath(String path) {
		output = new File(path);
	}
	
	public void append(String value) {
		values.add(value);
	}
	
	public void flush() throws IOException {
		BufferedWriter bw = new BufferedWriter(new FileWriter(output, true));
		for(int i = 0; i < values.size(); ++i) {
			bw.append(values.get(i));
			if(i+1 < values.size()) {
				bw.append(", ");
			}
		}
		bw.append(newLine);
		bw.flush();
		bw.close();
	}
}